package com.scfire.message

import com.scfire.baseInfo.Gson
import grails.converters.JSON

class SmsVerificationController {

	def CCPSMSService
	
	def sendDemo(){
		render (view : "index")
	}
	
    def sendSmsVerification() { 
		def gson = new Gson()
		
		def mobile = params.mobile
		
		if(!mobile){
			gson.setResult(false)
			gson.setCode(401)
			gson.setInfo(["text":"参数有误！"])
			render gson as JSON
		}
		
		def isSuccess = CCPSMSService.sendSMS(mobile)
		
		gson.setResult(isSuccess)
		if(isSuccess){
			gson.setCode(200)
			gson.setInfo(["text":"发送成功！"])
		}else{
			gson.setCode(401)
			gson.setInfo(["text":"发送失败！"])
		}
		render gson as JSON
	}
	
	def checkSmsVerification() {
		def mobile = params.mobile
		def code = params.code
		
		def gson = CCPSMSService.CodeCheck(mobile,code)
		
		render gson.isResult().toString()
	}
}
